package com.df.bpm.utils.entityCreator;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

public class test {
    public static void main(String[] args) throws IOException {
        HttpClient client = HttpClients.createDefault();
        HttpGet get = new HttpGet("http://localhost:9902/businessOverview/businessInformation/get");
//        HttpPost post = new HttpPost("http://192.168.0.11:8081/api/order/order/createOrderByBOM");
//        HttpPost post = new HttpPost("http://192.168.0.11:8081/api/auth/user/userLogon");
//        HttpPost post = new HttpPost("http://10.130.1.13:8081/api/order/order/dropOrder");

        // 添加请求头（如果需要）
        get.setHeader("Content-Type", "application/json");
//        post.setHeader("token", "faf72edf-c2e5-45b9-a3b4-c0bc5afb379a");

        // 发送请求体（如果需要）
//         StringEntity params = new StringEntity("{\"orderNumber\":\"test-240312-01\"," +
//                                                "\"tips\":\"测试数据3\"}","UTF-8");
//         post.setEntity(params);
//        NewOrderByBOMdto newOrder=new NewOrderByBOMdto();
//        newOrder.setOrderNumber("TESTSMT-1202403220051-01");
//        newOrder.setPartNumber("1.00.01.0185");
//        newOrder.setVersion("04");
//        newOrder.setPlanQty(207);
//        String [] mList={"2.03.00.0040-05",
//                "2.04.02.0210-00",
//                "2.04.04.0022-00",
//                "2.05.00.0096-00",
//                "2.06.02.0030-04",
//                "2.06.02.0032-04",
//                "2.10.00.0025-01",
//                "2.10.01.0153-01",
//                "2.11.01.0002-00"};
//        newOrder.setMaterialNumberList(mList);
//        ObjectMapper mapper = new ObjectMapper(); // 创建Jackson的ObjectMapper实例
//        try {
//            String json = mapper.writeValueAsString(newOrder); // 将DTO转换为JSON字符串
//            StringEntity sEntity = new StringEntity(json, ContentType.APPLICATION_JSON); // 创建StringEntity
//            post.setEntity(sEntity); // 设置请求体
//        } catch (JsonProcessingException e) {
//            e.printStackTrace();
//        }

        HttpResponse response = client.execute(get);
        HttpEntity entity = response.getEntity();
        int stateCode=response.getStatusLine().getStatusCode();
        System.out.println("响应码="+stateCode);
        if (entity != null) {
            String responseBody = EntityUtils.toString(entity);
            System.out.println("响应体="+responseBody);
        }

        EntityUtils.consume(entity); // 释放连接
    }
}
